home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-06-26 | 2.8 KB | 75 lines | [TEXT/GEOL] |
- Item 4950158 3-June-89 09:37
-
- From: CDA0373 AUC Lakehead U, Alan Day
-
- To: MACAPP.TEST MacApp SQA Team
-
- cc: MACAPP.TECH$ MACAPP Tech
-
- Sub: Comparing Objects |CDA0373
-
- Dear MacApp Team,
-
- I'd like to make a plea for a new general method for TObject, namely Compare.
- The default action would be something like the following:
-
- FUNCTION TObject.Compare(anObject:TObject):INTEGER;
- VAR p,q:LONGINT;
- BEGIN
- p:= LONGINT(SELF);
- q:= LONGINT(anObject);
- IF p < q THEN
- Compare:= kALessThanB
- ELSE IF p > q THEN
- Compare:= kAGreaterThanB
- ELSE { p = q }
- Compare:= kAEqualB;
- END;
-
- Such an implementation would require a minimal adjustment by making the UList.p
- constants global and defaulting TSortedList.Compare(item1,item2) to
- item1.Compare(item2).
-
- It would also allow easy compare methods for specialized objects. For example,
- if someone had Finder-styled named objects, i.e. objects with a string field,
- say TStrObject, one could override this Compare to produce
-
- FUNCTION TStrObject.Compare(anObject:TObject):INTEGER;OVERRIDE;
- VAR p,q:Str255;
- BEGIN
- p:= TStrObject(SELF).fString;
- q:= TStrObject(anObject).fString;
- IF p < q THEN
- Compare:= kALessThanB
- ELSE IF p > q THEN
- Compare:= kAGreaterThanB
- ELSE { p = q and the user didn't provide unique names }
- Compare:= INHERITED Compare(anObject);
- END;
-
- Perhaps the default TSortedList.Compare could even call, in debug mode,
- something like GetEltType(item1).Compare(item2) so that such lists always have
- a default sorting which, of course, can be still overridden.
-
- My rationale for this is that Compare seems to be a property of objects, not
- the lists which contain them; and that the above is a canonical content-free
- way to compare such, which has the crucial property that aItem.Compare(bItem) =
- kAEqualB if and only if aItem = bItem. Overrides can easily produce content
- sensitive versions of this: aItem.Compare(bItem) = kAEqualB if and only if
- "Content"(aItem) = "Content"(bItem) as in the TStrObject version above.
-
- Since I do not have 2.0ß9, I do not know if such a method has been implemented.
- Since my in-depth knowledge of programming philosophy and practices is limited,
- I cannot estimate all the ramifications of such a new method. I would like to
- suggest this method though, and if the idea is dumb find out why. [because I am
- seriously considering tweaking my MacApp to include this method]
-
- If this idea is reasonable, the minimal code and documentation changes required
- might make it a reasonable last minute inclusion for 2.0ß9. If deadlines are
- long past [and the idea holds water], could it be considered for the next
- release?
-
- Alan CDA0373
-
-
-